package com.ymatou.operate.trading.api.testcase;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.operate.trading.api.parameter.SyncOrderLogisticStatusRequestBean;
import com.ymatou.operate.trading.api.service.SyncOrderLogisticStatusRequestCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.database.sqlwapper.DefaultWapper;
/**
*优化清关状态同步接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SyncOrderLogisticStatusRequest{
	private static SyncOrderLogisticStatusRequestBean syncorderlogisticstatusrequestBean;
	private static SyncOrderLogisticStatusRequestCall syncorderlogisticstatusrequestCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("优化清关状态同步接口");
	}

	@Before
	public void caseUp() {
		syncorderlogisticstatusrequestBean=new SyncOrderLogisticStatusRequestBean();
		syncorderlogisticstatusrequestCall=new SyncOrderLogisticStatusRequestCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(syncorderlogisticstatusrequestCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SyncOrderLogisticStatusRequest_001() {
		Logger.start(true,"清关状态同步单条");
		try {
			List<Map> list = new DefaultWapper().getSyncOrderLogisticStatusRequestList(1);
			if(list.size()>=1)
			{
				Map item = list.get(0);
				List<String> LogisticsNos = new ArrayList<String>();
				LogisticsNos.add(item.get("billCode").toString());
				syncorderlogisticstatusrequestBean.setLogisticsNos(LogisticsNos);;
				syncorderlogisticstatusrequestBean.setIsDeliveredOfChina(true);;
				syncorderlogisticstatusrequestCall.setData(syncorderlogisticstatusrequestBean);
				syncorderlogisticstatusrequestCall.callService();
				
				int status = new DefaultWapper().getFrozenStatus(Integer.parseInt(item.get("iOrderId").toString()));
				
				Logger.verifyEquals(0, status, "验证返回");
				Map map = new DefaultWapper().getFrozenStatusInOrderFrozen(Integer.parseInt(item.get("iOrderId").toString()));
				
				Logger.verifyEquals(false, map.get("bFrozenAutoReceive"), "验证返回");
				Logger.verifyEquals(false, map.get("bPause"), "验证返回");
				Logger.verifyIsContains("\"Code\":200,\"BCode\":0", syncorderlogisticstatusrequestCall.getReturnData(), "验证返回串");
			}
			else
			{
				Logger.comment("数据库未查到合适数据。");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SyncOrderLogisticStatusRequest_002() {
		Logger.start(true,"清关状态同步多条");
		try {
			List<Map> list = new DefaultWapper().getSyncOrderLogisticStatusRequestList(1);
			if(list.size()>=1)
			{
				List<String> LogisticsNos = new ArrayList<String>();
				List<Integer> orders = new ArrayList<Integer>();
				for(int i=0;i<list.size();i++)
				{
					Map item = list.get(0);
					LogisticsNos.add(item.get("billCode").toString());
					orders.add(Integer.parseInt(item.get("iOrderId").toString()));
				}
				
				syncorderlogisticstatusrequestBean.setLogisticsNos(LogisticsNos);;
				syncorderlogisticstatusrequestBean.setIsDeliveredOfChina(true);;
				syncorderlogisticstatusrequestCall.setData(syncorderlogisticstatusrequestBean);
				syncorderlogisticstatusrequestCall.callService();
				
				for(int order :orders)
				{
					int status = new DefaultWapper().getFrozenStatus(order);
					
					Logger.verifyEquals(0, status, "验证返回");
					Map map = new DefaultWapper().getFrozenStatusInOrderFrozen(order);
					
					Logger.verifyEquals(false, map.get("bFrozenAutoReceive"), "验证返回");
					Logger.verifyEquals(false, map.get("bPause"), "验证返回");
				}
				
			}
			else
			{
				Logger.comment("数据库未查到合适数据。");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SyncOrderLogisticStatusRequest_003() {
		Logger.start(false,"同步已清关的");
		try {
			List<String> list=new ArrayList<String>();
			list.add("DB1132031Cdddddddddd");
			
			syncorderlogisticstatusrequestBean.setLogisticsNos(list);;
			syncorderlogisticstatusrequestBean.setIsDeliveredOfChina(true);;
			syncorderlogisticstatusrequestCall.setData(syncorderlogisticstatusrequestBean);
			syncorderlogisticstatusrequestCall.callService();
			
			Logger.verifyIsContains("\"Code\":200,\"BCode\":0", syncorderlogisticstatusrequestCall.getReturnData(), "验证返回串");
	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}